﻿
namespace MockingBird.Studio.UI.UserControls
{
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;
    using MockingBird.Studio.UI.UserControls.Model;

    internal class WsdlContextMenu : ContextMenuStrip
    {
        private WsdlLevel currentLevel;
        private string currentItemName;

        internal WsdlContextMenu() : base() { }
        internal WsdlContextMenu(IContainer container) : base(container) { }

        internal List<WsdlContextMenuItem> MenuItems { get; set; }

        internal void Clear()
        {
            this.Items.Clear();
        }

        internal void BuildUp(WsdlLevel level, string associatedItemName, List<CommandAction> commands)
        {
            this.currentLevel = level;
            this.currentItemName = associatedItemName;
            this.MenuItems = new List<WsdlContextMenuItem>();
            foreach (CommandAction command in commands)
            {
                WsdlContextMenuItem item = new WsdlContextMenuItem(command, new Size(220, 26));
                this.MenuItems.Add(item);
            }

            // Now add the menu items to the internal Items Array (defined in the parent control)
            this.Items.Clear();
            this.Items.AddRange(this.MenuItems.ToArray());
        }

        internal WsdlTreeEventArgs ConvertItemClickEvent(ToolStripItemClickedEventArgs e)
        {
            WsdlContextMenuItem menuItem = (WsdlContextMenuItem)e.ClickedItem;
            CommandAction targetAction = menuItem.Command;
            WsdlTreeEventArgs args = new WsdlTreeEventArgs();
            args.Command = targetAction;
            args.Level = this.currentLevel;
            args.ItemName = this.currentItemName;
            return args;

        }
    }
}
